/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2018
 */

package com.bm.console.business.impl;

import com.sys.console.cookie.Constant_Cookie;
import com.sys.console.pojo.Sys_User;
import com.sys.object.common.page.PageBean;

import com.bm.console.business.WebCityIndexService;
import com.bm.console.pojo.WebCityIndex;
import com.bm.console.pojo.mapper.WebCityIndexMapper;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sys.object.common.page.PageBean;

import javax.servlet.http.HttpServletRequest;

@Service
public class WebCityIndexServiceImpl implements WebCityIndexService {

    @Autowired
    WebCityIndexMapper webCityIndexMapper;

    @Autowired
    private HttpServletRequest request;

    @Override
    public PageBean queryPageList(WebCityIndex entity, PageBean page) throws Exception {
        int rowCount = webCityIndexMapper.selectByPageCount(entity);
        page.setRowCount(rowCount);
        entity.setOffset(page.getStartRow());
        entity.setLimit(page.getPerpage());
        page.setList(webCityIndexMapper.selectByPage(entity));
        return page;
    }

    public WebCityIndex queryByPrimaryKey(Integer id) throws Exception {
        return webCityIndexMapper.selectByPrimaryKey(id);
    }

    public int saveOrUpdate(WebCityIndex entity) throws Exception {
        Sys_User currentUser = (Sys_User)request.getSession().getAttribute(Constant_Cookie.CURRENT_USER_SESSION);
        if (entity.getId() != null && entity.getId() > 0) {
            entity.setUpdateTime(new Date());
            entity.setUpdateId(Long.valueOf(currentUser.getUid()));
            return this.webCityIndexMapper.updateByPrimaryKeySelective(entity);
        }
        entity.setCreateTime(new Date());
        entity.setCreateId(Long.valueOf(currentUser.getUid()));
        return this.webCityIndexMapper.insert(entity);
    }

    public int remove(Integer id) throws Exception {
        return this.webCityIndexMapper.deleteByPrimaryKey(id);
    }

    public int delete(Integer id) throws Exception {
        return this.webCityIndexMapper.deleteByPrimaryKey(id);
    }

    public int updateStatus(WebCityIndex entity) throws Exception {
        return this.webCityIndexMapper.updateByPrimaryKeySelective(entity);
    }

    public int updateStatus(String status, String[] ids)
            throws Exception {

        return 0;
    }


}
